package com.vim.modules.mall.controller;

import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageInfo;
import com.vim.common.base.BaseController;
import com.vim.modules.mall.model.base.CommonPage;
import com.vim.modules.mall.model.base.MallResponseEntity;
import com.vim.modules.mall.model.base.Page;
import com.vim.modules.mall.model.mallOrder.*;
import com.vim.modules.mall.service.MallOrderReturnApplyService;
import com.vim.modules.mall.service.MallOrderService;
import com.vim.modules.mall.service.remote.RemoteMallOrderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @作者 Administrator
 * @时间 2020-09-06 14:45
 * @版本 1.0
 */
@Controller
@RequestMapping(value = "/mall/order")
public class MallOrderController extends BaseController{

    @Autowired
    private MallOrderService mallOrderService;
    @Autowired
    private MallOrderReturnApplyService mallOrderReturnApplyService;

    /**
     * 列表页面
     */
    @RequiresPermissions(value = "mall:order:list")
    @RequestMapping(value = "/list")
    public String list(){
        return "mall/order/orderList";
    }

    /**
     * 列表数据
     * @param pageNo    页码
     * @param pageSize  每页数量
     */
    @RequiresPermissions(value = "mall:order:list")
    @RequestMapping(value = "/dataList")
    @ResponseBody
    public PageInfo<MallOrder> dataList(
            @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
        return mallOrderService.orderList(new Page(pageNo,pageSize));
    }

    /**
     * 订单详情
     */
    @RequiresPermissions(value = "mall:order:list")
    @RequestMapping(value = "/detail")
    public String detail(Long id, Model model){
        model.addAttribute("mallOrder", mallOrderService.orderDetail(id));
        return "mall/order/orderDetail";
    }

    /**
     * 订单发货form
     */
    @RequiresPermissions(value = "mall:order:delivery")
    @RequestMapping(value = "/deliveryForm")
    public String deliveryForm(Long id, Model model){
        model.addAttribute("mallOrder", mallOrderService.orderDetail(id));
        return "mall/order/orderDelivery";
    }

    /**
     * 订单发货
     */
    @RequiresPermissions(value = "mall:order:delivery")
    @RequestMapping(value = "/delivery")
    @ResponseBody
    public ResponseEntity delivery(Long id){
        mallOrderService.orderDelivery(id);
        return new ResponseEntity<>(success(), HttpStatus.OK);
    }
}
